package com.syni.mdd.yhd.common.all.service.impl.activity;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dao.jpa.activity.BmsMealPrizeDao;
import com.syni.mdd.yhd.common.all.entity.activity.BmsMealPrize;
import com.syni.mdd.yhd.common.all.service.activity.BmsMealPrizeService;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import com.syni.mdd.yhd.common.all.utils.SpecificationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @className
 * @description TOO
 * @Author hwq
 * @DATE 2019/9/23 10:34
 * @VERSION 1.0
 **/
@Service
public class BmsMealPrizeServiceImpl extends BaseService<BmsMealPrize, Integer> implements BmsMealPrizeService {

    @Autowired
    BmsMealPrizeDao bmsMealPrizeDao;

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public BmsMealPrizeDao getBaseDao() {
        return bmsMealPrizeDao;
    }

    @Override
    public List<BmsMealPrize> findAllPrizes() {
        Map<String,Object> conditionMap = new HashMap<>();
        conditionMap.put("isUse",Constants.COMMON_FLAG_TRUE_INT);
        conditionMap.put("remainNum_GTT",Constants.COMMON_FLAG_FALSE_INT);
        List<BmsMealPrize> bmsMealPrizes = bmsMealPrizeDao.findAll(new SpecificationUtils(conditionMap));
        return bmsMealPrizes;
    }

    @Override
    public BmsMealPrize findPrizeById(Integer id) {
        BmsMealPrize bmsMealPrize = bmsMealPrizeDao.findByIdAndIsUse(id,Constants.COMMON_FLAG_TRUE_INT);
        return bmsMealPrize;
    }

    @Override
    public BmsMealPrize findRemainNumAndVersion(Integer id) {
        return bmsMealPrizeDao.findRemainAndVersion(id);
    }
}
